<?php session_start(); /*Added by suwondo*/ ?>
<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"JS-6");
$currentPage = $_SERVER["PHP_SELF"];
mysql_select_db($database_con_gl, $con_gl);
$bid = $_GET['barang'];
$area = $_GET['area'];
list($namaarea) = mysql_fetch_row(mysql_query("select area from gl_area where id = '$area'"));
list($paket) = mysql_fetch_row(mysql_query("select barang from gl_barang where id = '$bid'"));
?>
<script type="text/javascript" src="js/jquery-1.4.js"></script>
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<h1>Data Kendaraan <?php if($area != '') echo "Area ".$namaarea;?></h1>

<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
	<tr valign="top" bgcolor="#FFFFFF" class="hide">
        <td colspan="11" align="right" style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;">
			<form id="search" name="search" method="post" action="">
			<!-- Edit by suwondo -->
			  Group Type Kendaraan
			  <select name="cr_type" id="cr_type" style="width:180px;">
                <option value="ALL" <?php if (!(strcmp("ALL", $_GET[cr_type]))) {echo "selected=\"selected\"";} ?>>Pilih Type</option>
                <option value="Innova" <?php if($_GET['cr_type']=='Innova') echo "selected"; ?>>Innova</option>
                <option value="Avanza" <?php if($_GET['cr_type']=='Avanza') echo "selected"; ?>>Avanza</option>
                <option value="Alphard"<?php if($_GET['cr_type']=='Alphard') echo "selected"; ?>>Alphard</option>
                <option value="APV" <?php if($_GET['cr_type']=='APV') echo "selected"; ?>>APV</option>
                <option value="Pregio" <?php if($_GET['cr_type']=='Pregio') echo "selected"; ?>>Pregio</option>
                <option value="Elf" <?php if($_GET['cr_type']=='Elf') echo "selected"; ?>>Elf</option>
                <option value="Camry" <?php if($_GET['cr_type']=='Camry') echo "selected"; ?>>Camry</option>
                <option value="Fortuner" <?php if($_GET['cr_type']=='Fortuner') echo "selected"; ?>>Fortuner</option>
                <option value="Pajero Sport" <?php if($_GET['cr_type']=='Pajero Sport') echo "selected"; ?>>Pajero Sport</option>
                <option value="Box Double" <?php if($_GET['cr_type']=='Box Double') echo "selected"; ?>>Box Double</option>
                <option value="Box Engkle" <?php if($_GET['cr_type']=='Box Engkle') echo "selected"; ?>>Box Engkle</option>
                <option value="Xenia" <?php if($_GET['cr_type']=='Xenia') echo "selected"; ?>>Xenia</option>
                <option value="Colt" <?php if($_GET['cr_type']=='Colt') echo "selected"; ?>>Colt</option>
                <option value="Byson" <?php if($_GET['cr_type']=='Byson') echo "selected"; ?>>Byson</option>
                <option value="Mercedes" <?php if($_GET['cr_type']=='Mercedes') echo "selected"; ?>>Mercedes</option>
                <option value="Jaguar" <?php if($_GET['cr_type']=='Jaguar') echo "selected"; ?>>Jaguar</option>
          
              </select>
			  Pilih Tahun
			
			  <select name="tahun" id="tahun">
                
                <?php
				$now = date("Y");
				
				for($i=$now; $i>$now-17; $i--){				    
					echo '<option value="'.$i.'"'.($_GET[tahun] ==$i ? 'selected="selected"' :'').'>'.$i.'</option>';
				}
				?>
              </select>
			  Pencarian data : 
	    <label>
					<input name="cr_txt" type="text" id="cr_txt" placeholder="Find by: no polisi" onclick="this.select(); $(this).autocomplete('components/kendaraan/search.autocomplete.php?barang=<?php echo $bid; ?>&area=<?php echo $area; ?>', { width: 330 });" size="45" maxlength="100" onkeyup="javascript: $(this).autocomplete('components/kendaraan/search.autocomplete.php?barang=<?php echo $bid; ?>&area=<?php echo $area; ?>', { width: 330 }); $(this).result(function(event, data, formatted){ idx = formatted.split(' - '); window.location.href='index.php?component=kendaraan&task=list&barang=<?php echo $bid; ?>&area=<?php echo $area; ?>&open=window&cr_kel=ALL&cr_txt='+idx[1]; });" <?php echo $_REQUEST['cr_txt'];?> />
				</label>
				<label><input name="Search" type="submit" id="Search" value="Search" /></label>
			</form>
		<?php
		if(isset($_POST['Search'])) {
			echo "<script>window.location=\"index.php?component=kendaraan&task=list&barang=$bid&area=$area&open=window&tahun=".$_POST[tahun]."&cr_type=".$_POST[cr_type]."&cr_kel=ALL&cr_txt=".str_replace(" ","+",$_POST[cr_txt])."\";</script>";
		}
		?>		</td>
	</tr>
	<tr>
		<th width="500"><strong>Tipe Kendaraan</strong></th>
		<th width="219"><strong>Tahun</strong></th>
		<th width="219"><strong>No. Polisi</strong></th>
		<th width="119"><strong>Unit Stok</strong></th>
		<th width="119"><strong>Cabang</strong></th>
		<th width="132" align="center" class="hide"><strong>Aksi</strong></th>
	</tr>
	<?php
	$type = $_REQUEST['cr_type'];
    $_tahun = $_REQUEST['tahun'];
	if($_REQUEST['tahun'] == '')
	{
		$_tahun = date("Y"); 
		//echo $_tahun;
	}
	if(trim($_REQUEST['cr_txt']) != '')
	{
		$key = trim($_REQUEST['cr_txt']);
		
	}
	else
	{
		$key = '-';
	}
	
	
	if($bid == 'false'){
		$str = "select distinct a.id, a.tipekendaraan, b.tahun, b.nopolisi, b.area, b.cabang,CASE b.unitstok
                   WHEN '1' THEN 'Corp'
				   WHEN '2' THEN 'Retail'
				   WHEN '3' THEN 'Tugas Kantor'
				   ELSE 'Ops /UGC.'
      END AS Unit from gl_tipekendaraan as a inner join gl_masterkendaraan as b on (a.id = b.tipekendaraan) inner join gl_jenbar as c on (a.id = c.jenis) where b.area = '$area' and a.tipekendaraan like '%$type%'";
		if(!strstr($_SESSION[akses],'A-1-4')) {
			$str .= " and b.cabang = '$_SESSION[lokasi]' ";
		}
		$str .= " order by b.nopolisi asc";
		$query = mysql_query($str) or die (mysql_error()); 
	}else{
	
		$str = "select distinct a.id, a.tipekendaraan, b.tahun, b.nopolisi, b.area, b.cabang,CASE b.unitstok
                   WHEN '1' THEN 'Corp'
				   WHEN '2' THEN 'Retail'
				   WHEN '3' THEN 'Tugas Kantor'
				   ELSE 'Ops /UGC.'
      END AS Unit from gl_tipekendaraan as a inner join gl_masterkendaraan as b on (a.id = b.tipekendaraan) inner join gl_jenbar as c on (a.id = c.jenis) where c.barang='18' AND b.area = '$area' and a.tipekendaraan like '%$type%'";
		if($key == '-')
		{
			$str .= "and (b.nopolisi like '%$key%' or  b.tahun = '$_tahun')";
		}
		else
		{
     		$str .= "and (b.nopolisi like '%$key%' and  b.tahun = '$_tahun')";
		}
		
		//print_r($str);
		if(!strstr($_SESSION[akses],'A-1-4')) {
			$str .= " and b.cabang = '$_SESSION[lokasi]' ";
		}
		$str .= " order by b.unitstok";

		$query = mysql_query($str) or die (mysql_error()); 
		} 
		while(list($id, $tipe, $tahun, $nopolisi, $area, $cabang,$Unit) = mysql_fetch_row($query)){
		echo "<tr>";
		list($namaarea) = mysql_fetch_row(mysql_query("select area from gl_area where id='$area'"));
		list($namagudang) = mysql_fetch_row(mysql_query("select gudang from gl_gudang where id='$cabang'"));
		echo "<td>$tipe</td><td>$tahun</td><td>$nopolisi</td><td>$Unit</td><td>$namagudang</td><td align='center'><input type='button' value='pilih' onclick=\"javascript: window.opener.document.getElementById('kendaraan').value='$nopolisi'; window.opener.document.getElementById('txtkendaraan').value='$nopolisi';"; 
		if($bid !== 'false'){
		echo " window.opener.getHargaKendaraan(); window.opener.getBiayaBBM(); window.opener.getBiayaTol(); window.opener.getBiayaParkir(); window.opener.getBiayaSupir(); window.opener.getBiayaAkomodasi(); window.opener.getBiayaOther(); window.opener.getTotal(); window.opener.getGrandTotal(); ";
		}
		echo "window.close(1000);\" /></td>";
		echo "</tr>";
	}
	?>
 </table>
